<% set null off set date ymd set cent on dateto =orequest.querystring("dateto") thecustomer =nvl(orequest.querystring("customerid"),[]) thesaleman =nvl(orequest.querystring("saleman"),[]) reportbase =orequest.querystring("reportbase") wheretext=[] thecustomername=[] thesalemanname=[] REPTTITLE=[DEBIT SALE SUMMARY] REPTSECLINE=[] returntxt=[No records found with current criteria!
] if isnull(dateto) or empty(ctod(dateto)) dateto=orequest.form("dateto") endif pdate2=ctod(dateto) set date british categoryname= allt(nvl(orequest.querystring("category"),'')) classname= allt(nvl(orequest.querystring("class"),'')) if isnull(pdate2) or empty(pdate2) tsql=[select top 1 date from (']+dbclocation+[invoice') order by date desc into cursor tmp] &tsql pdate2=date endif if not empty(pdate2) wheretext=wheretext+[and x.date=pdate2 ] REPTSECLINE=[DATE: ]+TRANSFORM(PDATE2) returntxt=returntxt+[ date: ]+TRANSFORM(PDATE2) endif if not empty(thesaleman) wheretext=wheretext+[and x.saleman=thesaleman ] tsql=[select x.name from (']+dbclocation+[accounts') x where x.accountid=']+thesaleman+[' into cursor tmp] &tsql thesalemanname=allt(name) REPTSECLINE=[REF: ]+thesalemanname+[ ]+REPTSECLINE returntxt=returntxt+[ ref: ]+thesalemanname endif if not empty(thecustomer) wheretext=wheretext+[and x.customer=thecustomer ] tsql=[select x.name from (']+dbclocation+[accounts') x where x.accountid=']+thecustomer+[' into cursor tmp] &tsql thecustomername=allt(name) REPTSECLINE=THECUSTOMERNAME+[ (]+THECUSTOMER+[)]+[
]+REPTSECLINE returntxt=returntxt+[ client: ]+thecustomername endif if not empty(wheretext) wheretext=[where ]+subst(wheretext,5) endif tstr=[

]+REPTTITLE+[

]+reptsecline+[] ordertext=" order by y.itemid, y.desc " tsql=[Select y.itemid, y.desc, y.qty, y.bonus, y.transid, y.sr_no ] tsql=tsql+[ from (']+dbclocation+[invoice') x inner join (']+dbclocation+[invdata') y on (x.transid=y.transid) ]+wheretext+[ order by y.itemid, y.desc into cursor tempcursor ] && table ]+addbs(oprop.appstartpath)+[temp\tempcursor.dbf] try &tsql catch tstr=[Has error] endtry *strtofile('hello', addbs(oprop.appstartpath)+[temp\debitsaleerror.txt]) if _tally=0 * oresponse.write(tsql) return returntxt endif store 0 to tthissale, tthisreturns, tthiscost, tthisprofet select [tempcursor] hasbonus=.f. go TOP do while not eof() if not empty(bonus) hasbonus=.t. exit endif skip enddo tstr=tstr+[]+iif(hasbonus,[],[])+[] go top do while not eof() THISITEM=nvl(itemid,[itemid]) THISitemname=NVL(desc,[desc]) thisqty=0 thisbonus=0 do while nvl(itemid,[itemid])=thisitem and THISitemname=NVL(desc,[desc]) and not eof() thisqty=thisqty+nvl(QTY,0) thisbonus=thisbonus+nvl(bonus,0) skip enddo thisqty=icase(thisqty=round(thisqty,0),round(thisqty,0),thisqty=round(thisqty,2),round(thisqty,2),thisqty=round(thisqty,3),round(thisqty,3),round(thisqty,4)) thisbonus=icase(thisbonus=round(thisbonus,0),round(thisbonus,0),thisbonus=round(thisbonus,2),round(thisbonus,2),thisbonus=round(thisbonus,3),round(thisbonus,3),round(thisbonus,4)) thistotal=thisqty+thisbonus thislinestr=[] thislinestr=thislinestr+[] thislinestr=thislinestr+[] thislinestr=thislinestr+[] if hasbonus thislinestr=thislinestr+[] thislinestr=thislinestr+[] endif thislinestr=thislinestr+[]+chr(13) tstr=tstr+nvl(thislinestr,transform(transid)+[ ]+itemid) * strtofile(tstr,(addbs(oprop.appstartpath)+[temp\debitsaleerror.txt])) *oresponse.write([
Item#Item NameQTYFREET.QTY
]+iif(empty(THISITEM),[NO ITEM ID],ALLT(THISITEM))+[]+iif(empty(THISitemname),[NO ITEM NAME],ALLT( THISitemname))+[]+iif(empty(thisqty),[ ],transform(thisqty))+[]+iif(empty(thisbonus),[ ],transform(thisbonus))+[]+iif(empty(thistotal),[ ],transform(thistotal))+[
]+thislinestr+[
]) enddo tstr=tstr+[] *strtofile(tstr,(addbs(oprop.appstartpath)+[temp\debitsaleerror.txt])) %> SSSoft™ - <%=XCOMPANY.NAME%> Receipt
<%=tstr%>